package main

import (
	"fmt"
	"strconv"
	"sync"
	"time"
)

type UserAges struct {
	ages map[string]int
	sync.Mutex
}

func (u *UserAges) Add(name string, age int) {
	u.Lock()
	defer u.Unlock()
	u.ages[name] = age
}
func (u *UserAges) Get(name string) int {
	u.Lock()
	defer u.Unlock()
	v, ok := u.ages[name]
	if ok {
		fmt.Println("vv:", v)
		return v
	}
	fmt.Println(-1)
	return -1
}

func add(u *UserAges) {
	for i := 0; i < 100; i++ {
		go u.Add("zhang:"+strconv.Itoa(i), i)
	}
}
func dep(u *UserAges) {
	for i := 0; i < 100; i++ {
		go u.Get("zhang:" + strconv.Itoa(i))
	}
}
func main() {
	u := new(UserAges)
	u.ages = make(map[string]int)
	go add(u)
	go dep(u)
	time.Sleep(time.Second * 3)
}
